﻿using System.Xml;

namespace Builderator.Core
{
    public class TimeInterval
    {
        public int hours;
        public int minutes;
        public int seconds;

        public TimeInterval(string time)
        {
            XmlDocument xmlDoc = new XmlDocument();

            if (time == string.Empty)
                return;

            xmlDoc.LoadXml(time);

            XmlElement rootElement = xmlDoc.DocumentElement;

            this.hours = int.Parse(rootElement.GetAttribute("Hours"));

            this.minutes = int.Parse(rootElement.GetAttribute("Minutes"));

            this.seconds = int.Parse(rootElement.GetAttribute("Seconds"));
        }

        public override string ToString()
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlElement rootElement = xmlDoc.CreateElement("TimeInterval");

            rootElement.SetAttribute("Hours", this.hours.ToString());

            rootElement.SetAttribute("Minutes", this.minutes.ToString());

            rootElement.SetAttribute("Seconds", this.seconds.ToString());

            xmlDoc.AppendChild(rootElement);

            return xmlDoc.InnerXml;
        }
    }
}